﻿CREATE PROCEDURE [dbo].[spWH_UpdatePerfmonRownum]
AS

IF EXISTS (SELECT TOP 1 [perf_id] FROM [dbo].[tblWH_Perfmon] WHERE [rownum] IS NULL)
BEGIN
	UPDATE		t1
	SET			[rownum] = [iRowNumber]
	FROM		(
				SELECT		ROW_NUMBER() OVER (ORDER BY	server_ssd_id, date_inserted) iRowNumber,
							[perf_id],
							[rownum]
				FROM		[dbo].[tblWH_Perfmon]
				) t1
	WHERE		ISNULL([rownum], -1) <> [iRowNumber]
END